/* -------------------------------------- 

A1_SummaryStatistics.do

by: Kristy A.E. Jansen

This do-file: Prepare summary stats Jansen (2024)
	1. Table 1
	2. Figure 3
	3. Table IA1

-------------------------------------- */

/* Initialization */
clear all
set more off
capture log clear _all

global root "~/RFS_replication" // *** NEED TO CHANGE THIS TO CORRECT FILE PATH ***
global main_data $root/Data

/* Load ado-files */
do "$root/adofiles/bytwoway.ado" 

/* Load Data */
use "$main_data/pseudo_data_part1.dta", clear

/* -------------------------  Summary Statistics ------------------------- */ 

display("Table 1: Summary statistics")

/* Assets */ 
replace AUMfundyq_all = AUMfundyq_all/1000
replace AUMfundyq_direct = AUMfundyq_direct/1000

estpost tabstat AUMfundyq_all, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat AUMfundyq_direct, by(group) statistics(mean sd median) columns(statistics) listwise

/* Asset allocation */
estpost tabstat frac_gov_fundyq, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_corp_fundyq, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_stocks_fundyq, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat dur_port_nominal, by(group) statistics(mean sd median) columns(statistics) listwise

/* Liabilities */
replace inverse_fr = inverse_fr*100

estpost tabstat liab_dur, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat inverse_fr, by(group) statistics(mean sd median) columns(statistics) listwise

/* -------------------------  Long-term Bond Holdings ------------------------- */

display("Figure 3: Long-term bond holdings over time")

preserve
sum liab_dur_2011q2
gen dummy_LT = 0 if liab_dur_2011q2 < `r(mean)'
replace dummy_LT = 1 if liab_dur_2011q2 > `r(mean)' & liab_dur_2011q2!=.

collapse (mean) frac_mat_bucket_fundyq_7 frac_mat_close_20_fundyq, by(dummy_LT yq)

/* Long-term */
bytwoway (line frac_mat_bucket_fundyq_7 yq), by(dummy_LT) xline(210) ytitle("Fraction long-term bonds") ///
legend(subtitle("") pos(6) col(3) label(1 "Long liability duration") label(2 "Short liability duration"))
/* 20-year */
bytwoway (line frac_mat_close_20_fundyq yq), by(dummy_LT) xline(210) ytitle("Fraction 20-year bonds") ///
legend(subtitle("") pos(6) col(3) label(1 "Long liability duration") label(2 "Short liability duration"))
restore

/* -------------------------  Extended Summary Statistics ------------------------- */

display("Table IA1: Summary statistics - extended") 

estpost tabstat frac_mat_bucket_fundyq_7, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_mat_close_20_fundyq, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_short_fundyq, by(group) statistics(mean sd median) columns(statistics) listwise

estpost tabstat CreditRatingCORP_nominal, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat CreditRatingGOV_nominal, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_HY_fundyq, by(group) statistics(mean sd median) columns(statistics) listwise

estpost tabstat frac_NL, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_DE, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_FR, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_AT, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_BE, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_FI, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_DK, by(group) statistics(mean sd median) columns(statistics) listwise
estpost tabstat frac_vul, by(group) statistics(mean sd median) columns(statistics) listwise

estpost tabstat vol_FR, by(group) statistics(mean sd median) columns(statistics) listwise

